package com.example.dubbo.demo.consumer.service.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.example.dubbo.demo.api.domain.UserAddress;
import com.example.dubbo.demo.api.service.OrderService;
import com.example.dubbo.demo.api.service.UserService;

import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 1、将服务提供者注册到注册中心
 *      1)、导入dubbo的依赖（2.6.2）\操作zookeeper的客户端（curator）
 *      2)、
 *
 * 2、让服务消费者去注册中心订阅服务提供者的服务地址
 */
@Service
public class OrderServiceImpl implements OrderService {

    //@Autowired
    @Reference //由dubbo在注册中心引入服务
    UserService userService;


    @Override
    public List<UserAddress> initOrderBoot(String userId) {
        //1、查询用户的收获地址
        //跨module调用userServiceImpl，需要用到dubbo
        System.out.println("用户id：" + userId);
        //userService远程调用提供者的getUserAddressList方法
        return userService.getUserAddressList(userId);
    }

    public List<UserAddress> hello(){
        UserAddress userAddress = new UserAddress(1, "测试", "测试", "测试", "测试", "Y");
        List<UserAddress> list = new ArrayList<>();
        list.add(userAddress);
        return list;
    }
}
